<?php

namespace App\Services\Image;


use Intervention\Image\Constraint;
use Intervention\Image\ImageManagerStatic;

class Compress
{
    const DEFAULT_IMG_QUALITY = 80;

    /**
     * 压缩后好上传给 FACE PP
     * @param $image_path
     * @param $width
     * @param null $height
     * @param int $quality_percentage
     */
    public static function handle($image_path , $width , $height = null, $quality_percentage = self::DEFAULT_IMG_QUALITY )
    {
        ImageManagerStatic::make( $image_path )
            ->resize($width, $height, function (Constraint $constraint) {
                $constraint->aspectRatio();
                $constraint->upsize();
            })
            ->save( $image_path  , $quality_percentage );
    }

}
